package com.heima.wemedia.scan.listener;

import com.heima.model.wemedia.constants.KafkaMessageConstants;
import com.heima.wemedia.scan.service.WmNewsAutoScanService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.apache.kafka.clients.consumer.ConsumerRecord;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

@Slf4j
@Component
public class NewsAutoScanListener {
    @Resource
    private WmNewsAutoScanService wmNewsAutoScanListener;

    @KafkaListener(topics = KafkaMessageConstants.WM_NEWS_AUTO_SCAN_TOPIC, groupId = "WM_NEWS_AUTO_SCAN")
    public void wmNewsAutoScan(ConsumerRecord<String, String> record) {
        String value = record.value();
        log.info("接收到消息 , 消息内容:{}", record.value());
        if (StringUtils.isNotBlank(value)) {
            log.info("开始进行文章自动审核 , 文章ID:{}", value);
            wmNewsAutoScanListener.autoScanNews(Long.valueOf(value));
            log.info("文章自动审核完成 , 文章ID:{}", value);
        }
    }
}
